package com.chaosj.memory.handlers;

import com.alibaba.fastjson.JSONObject;
import com.chaosj.memory.dto.WriterDto;
import com.chaosj.tools.JsonTools;
import com.chaosj.webmagic.scrape.WriterBookHandler;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;

/**
 * @className: ScapeSiteHandler
 * @description:
 * @author: caoyangjie
 * @date: 2022/1/4
 **/
@Slf4j
public class ScrapeWriterHandler extends AbstractToolHandler<WriterDto>{
    WriterBookHandler handler = new WriterBookHandler();
    @Override
    public String name() {
        return "writer";
    }

    @Override
    public void handler(WriterDto req, StringBuffer outBuffer) {
        req.getScrapeUris().forEach(uri->{
            handler.setCtx((JSONObject) JSONObject.toJSON(req));
            handler.scrape(uri);
        });
    }

    @Override
    public WriterDto cmd2Dto(String[] args) {
        return new WriterDto(Arrays.asList(args));
    }
}
